﻿using AiBLSmartEdu.Module.AIMentalHealthSelfAssessment.API.DTOs;
using AiBLSmartEdu.Module.AIMentalHealthSelfAssessment.API.Services;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AiBLSmartEdu.Module.AIMentalHealthSelfAssessment.API.Controllers;

/// <summary>
/// AI心理健康自评问卷
/// </summary>
[AllowAnonymous]
public class AIMentalHealthController : BaseModuleController
{
    private readonly PsychologicalTestService _psychologicalTestService;

    public AIMentalHealthController(PsychologicalTestService psychologicalTestService)
    {
        _psychologicalTestService = psychologicalTestService;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<MentalHealthSelfAssessmentOutputModel>> PaginationAsync([FromQuery] MentalHealthSelfAssessmentPaginationFilter filter)
    {
        return await _psychologicalTestService.PageAsync(filter);
    }

    /// <summary>
    /// 生成心理测试题
    /// </summary>
    /// <param name="request">用户描述</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result<PsychologicalQuestions>> GenerateQuestionsAsync(PsychologicalTestRequest request)
    {
        return await Result<PsychologicalQuestions>.SucceedAsync(
        await _psychologicalTestService.GenerateQuestionsAsync(request));
    }

    
    /// <summary>
    /// 分析用户心理健康状况
    /// </summary>
    /// <param name="request">请求参数</param>
    /// <returns></returns>
    [HttpPost("Analyze")]
    public async Task<Result<AnalysisResult>> AnalyzeAsync(TestAnswerRequest request)
    {
        return await Result<AnalysisResult>.SucceedAsync(
        await _psychologicalTestService.AnalyzeAnswersAsync(request));
    }

    /// <summary>
    /// 删除测试记录
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    public async Task<Result> DeleteAsync(long id)
    {
        await _psychologicalTestService.DeleteAsync(id);
        return await Result.SucceedAsync();
    }
}
